package com.design.pattern.proxy.dynamicproxy;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {

    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public ProxyFactory() {
    }

    public Object getProxyInstance() {
        Object proxyInstance = Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("动态代理开始...");
                Object o = method.invoke(target, args);
                System.out.println("动态代理结束..." + o);
                return o;
            }
        });
        return proxyInstance;
    }
}
